package com.example.maple.ccsclient.presenter;

import android.content.Context;

import com.example.maple.ccsclient.app.SearchActivity;
import com.example.maple.ccsclient.interfaces.ISearchView;
import com.example.maple.ccsclient.model.AllDataInfoUtils;
import com.example.maple.ccsclient.model.DataModel;
import com.example.maple.ccsclient.model.ISendData;
import com.example.maple.ccsclient.model.PicModel;

import java.util.List;

/**
 * Created by maple on 2016/7/4.
 */
public class SearchPresenter {

	Context mContext = null;
	ISearchView mISearchView = null;
	AllDataInfoUtils mAllDataInfoUtils = null;

	public SearchPresenter(Context context, ISearchView iSearchView) {
		mContext = context;
		mISearchView = iSearchView;
		mAllDataInfoUtils = new AllDataInfoUtils(mContext);
	}

	//刷新数据
	public void refresh(String strs) {
		//显示加载
		mISearchView.startAnimation();

		//获取网络数据
		mAllDataInfoUtils.getCharPic(false,strs, new ISendData() {
			@Override
			public void sendData(Object o) {
				DataModel<List<PicModel>> dataModel = (DataModel<List<PicModel>>) o;

				if (dataModel.getStatus() == 1) {
					mISearchView.showSearchPic(dataModel.getData());
				} else {
					mISearchView.showDialog(dataModel.getInfo());
				}
				mISearchView.stopAnimation();
			}
		});
	}


}
